import 'package:json_annotation/json_annotation.dart';

part 'ali_pay_pre_order.g.dart';

@JsonSerializable()
class AliPayPreOrder {
  @JsonKey(defaultValue: 0)
  final int status;
  @JsonKey(defaultValue: '')
  final String message;
  final Data? data;

  AliPayPreOrder({
    required this.status,
    required this.message,
    this.data,
  });

  factory AliPayPreOrder.fromJson(Map<String, dynamic> json) =>
      _$AliPayPreOrderFromJson(json);

  Map<String, dynamic> toJson() => _$AliPayPreOrderToJson(this);
}

@JsonSerializable()
class Data {
  @JsonKey(name: 'app_id', defaultValue: '')
  final String appId;
  @JsonKey(name: 'biz_content')
  final BizContent? bizContent;
  @JsonKey(defaultValue: '')
  final String charset;
  @JsonKey(defaultValue: '')
  final String method;
  @JsonKey(defaultValue: '')
  final String timestamp;
  @JsonKey(defaultValue: '')
  final String version;
  @JsonKey(defaultValue: '')
  final String prikey;
  @JsonKey(name: 'notify_url', defaultValue: '')
  final String notifyUrl;

  Data({
    required this.appId,
    this.bizContent,
    required this.charset,
    required this.method,
    required this.timestamp,
    required this.version,
    required this.prikey,
    required this.notifyUrl,
  });

  factory Data.fromJson(Map<String, dynamic> json) =>
      _$DataFromJson(json);

  Map<String, dynamic> toJson() => _$DataToJson(this);
}

@JsonSerializable()
class BizContent {
  @JsonKey(name: 'timeout_express', defaultValue: '')
  final String timeoutExpress;
  @JsonKey(name: 'product_code', defaultValue: '')
  final String productCode;
  @JsonKey(name: 'total_amount', defaultValue: '')
  final String totalAmount;
  @JsonKey(defaultValue: '')
  final String body;
  @JsonKey(defaultValue: '')
  final String subject;
  @JsonKey(name: 'out_trade_no', defaultValue: 0)
  final int outTradeNo;

  BizContent({
    required this.timeoutExpress,
    required this.productCode,
    required this.totalAmount,
    required this.body,
    required this.subject,
    required this.outTradeNo,
  });

  factory BizContent.fromJson(Map<String, dynamic> json) =>
      _$BizContentFromJson(json);

  Map<String, dynamic> toJson() => _$BizContentToJson(this);
}
